{extend name="/layouts/base" /}

{block name="title"}搜索记录 - {$CONFIG->SITE->title}{/block}

{block name="content"}
<div id="log" class="container-xxl">
    
    <div class="row  mt-md-4 mt-2">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <span class="card-title mb-0">本日API调用情况</span>
                </div>
                <div class="card-body">
                    
                    <div class="dropdown float-end">
                        <a href="javascript:;" class="dropdown-toggle arrow-none card-drop" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="mdi mdi-dots-vertical"></i>
                        </a>
                        <div class="dropdown-menu dropdown-menu-end">
                            <a v-on:click="initData(1,true)" href="javascript:;" class="dropdown-item">
                                <i class="mdi mdi-autorenew me-1"></i>刷新
                            </a>
                        </div>
                    </div>
                    
                    <div class="row pb-2">
                        <div class="com-md-6">
                            <div class="card-body pt-0 pb-0">
                                <div class="app-search d-block">
                                    <div class="input-group">
                                        <input v-model="search_value" v-on:keyup.enter.native="initData(1,true)" type="text" class="form-control mw-250" placeholder="IP | API | 类型" data-bs-toggle="tooltip" data-original-title="支持模糊查询">
                                        <span class="mdi mdi-magnify"></span>
                                        <div class="input-group-append">
                                            <button v-on:click="initData(1,true)" class="btn btn-primary" type="button">搜索</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 加载动画 开始 -->
                    <div v-if="is_load" class="table-responsive is_load mb-2 flex-center">
                        <div class="spinner-border text-primary m-1" role="status"></div>
                        <div>加载中...</div>
                    </div>
                    <!-- 加载动画 结束 -->
                    
                    <div v-else-if="!is_load" class="table-responsive-sm">
                        <table class="table custom table-centered mb-0">
                            <thead>
                                <tr>
                                    <th>
                                        <div class="custom-control custom-checkbox">
                                            <input v-on:click="selectAll" type="checkbox" class="custom-control-input" id="select-all">
                                            <label class="custom-control-label" for="select-all"></label>
                                        </div>
                                    </th>
                                    <th>IP</th>
                                    <th>类型</th>
                                    <th>API</th>
                                    <th>时间</th>
                                    <th>系统</th>
                                    <th>浏览器</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr v-for="(item, index) in items.data" :key="index">
                                    <td>
                                        <div class="custom-control custom-checkbox">
                                            <input :name="item.id" type="checkbox" class="custom-control-input checkbox-item" :id="'select-' + item.id">
                                            <label class="custom-control-label" :for="'select-' + item.id"></label>
                                        </div>
                                    </td>
                                    <td>
                                        <span v-on:click="runSearch(item.ip)" class="pointer">
                                            {{item.ip}}
                                        </span>
                                    </td>
                                    <td>
                                        <span v-on:click="runSearch(item.method)" class="pointer">
                                            {{item.method}}
                                        </span>
                                    </td>
                                    <td>
                                        <span v-on:click="edit = item" class="pointer" data-bs-toggle="modal" data-bs-target="#fill-edit-modal">
                                            {{item.url}}
                                        </span>
                                    </td>
                                    <td>{{natureTime(item.create_time)}}</td>
                                    <td>
                                        <span class="badge badge-warning-lighten">{{item.expand.agent.os.system}}</span>
                                        <span class="badge badge-info-lighten">{{item.expand.agent.os.version}}</span>
                                    </td>
                                    <td>
                                        <span class="badge badge-primary-lighten">{{item.expand.agent.browser.kernel}}</span>
                                        <span class="badge badge-warning-lighten">{{item.expand.agent.browser.version}}</span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    
                    <div class="flex space-between align-items-center mt-2">
                        <div class="d-none d-md-block">
                            共 {{items.page}} 页 {{items.count}} 条数据
                        </div>
                        <div v-if="!page_is_load && is_page_show" class="btn-group">
                            <button v-on:click="initData(1)" type="button" class="btn btn-light btn-sm"><i class="mdi mdi-chevron-left"></i></button>
                            <button v-for="(item, index) in page_list" :key="index" v-on:click="initData(item)" :class="(page == item) ? 'btn btn-sm btn-primary' : 'btn btn-sm btn-light'">
                                {{item}}
                            </button>
                            <button v-on:click="initData(items.page)" type="button" class="btn btn-light btn-sm"><i class="mdi mdi-chevron-right"></i></button>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
    
    <!-- 模态框 - 结束 -->
    <div id="fill-edit-modal" class="modal fade" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="fill-primary-modalLabel" aria-hidden="true">
        <!-- modal-dialog-centered -->
        <div class="modal-dialog">
            <div class="modal-content modal-filled bg-primary">
                <div class="modal-header">
                    <h4 class="modal-title" id="fill-primary-modalLabel">IP: {{edit.ip}} - 请求参数</h4>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="table-responsive">
                        <table class="table custom table-sm table-centered mb-0 font-14 text-white">
                            <thead>
                                <tr>
                                    <th>参数</th>
                                    <th>值</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr v-for="(item, index) in edit.params">
                                    <td>{{index}}</td>
                                    <td>{{decodeURIComponent(item)}}</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="row my-2">
                        <div class="col-lg-12">
                            <div class="float-start">
                                API：{{filterQuery(edit.url)}}
                            </div>
                            <div class="float-end">请求方式：{{edit.method}}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 模态框 - 结束 -->
</div>
{/block}

{block name="script"}
<script src="{$CONFIG->ROOT}js/pages/log.js?v={$CONFIG->VERSION}"></script>
{/block}